package com.humngyang.com.hmy.service;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.humngyang.com.hmy.entity.Artical;
import com.humngyang.com.hmy.mapper.ArticalMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class ArticalService {

    @Autowired
    ArticalMapper articalMapper;

    public void addArtical(Artical artical) {
        artical.setId(UUID.randomUUID().toString().replace("-", ""));
        articalMapper.insert(artical);
    }

    public List<Artical> getAllArticals() {
        List<Artical> list = articalMapper.selectList(new QueryWrapper<Artical>());
        return list;
    }

    public Artical getArticalbyId(String id) {
        Artical artical = (Artical) articalMapper.selectById(id);
        return artical;
    }

    //条件查询
    public List<Artical> getAllArticalLike(Wrapper wrapper) {
        List<Artical> articals = articalMapper.selectList(new QueryWrapper<Artical>().like("name", "x"));
        return articals;
    }


//        分页查询

    public void selectPage() {
        Page<Artical> page = new Page<>(1, 2);
        IPage<Artical> articalIPage = articalMapper.selectPage(page, null);
        System.out.println("总条数====" + articalIPage.getTotal());
        System.out.println("当前页数====" + articalIPage.getCurrent());
        System.out.println("分页查询内容====" + articalIPage.getRecords());
        System.out.println("当前每页显示数====" + articalIPage.getPages());
    }

}
